-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix get_canonical/absolute/normalize_path() functions #100
Conversation
e965896
to
c0793a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
base/fs_unix.h
Outdated
@@ -208,11 +209,24 @@ std::string get_user_docs_folder() | |||
|
|||
std::string get_canonical_path(const std::string& path) | |||
{ | |||
std::string full = get_absolute_path(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'full' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]
std::string full = get_absolute_path(path); | |
std::string const full = get_absolute_path(path); |
return std::string(); | ||
} | ||
|
||
std::string get_absolute_path(const std::string& path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'get_absolute_path' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
std::string get_absolute_path(const std::string& path)
^
Additional context
base/fs_unix.h:220: make as 'inline'
std::string get_absolute_path(const std::string& path)
^
const std::string full = get_absolute_path(path); | ||
DWORD attr = ::GetFileAttributes(from_utf8(full).c_str()); | ||
if (attr != INVALID_FILE_ATTRIBUTES) | ||
return full; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: constness of 'full' prevents automatic move [performance-no-automatic-move]
return full;
^
Several refactors in this commit: - Moved is_path_separator() function and path_separator as a constexpr to the header file - Added path_separators string (for Windows, which includes \ and /) - get_canonical_path() works only when the file exists (returns an empty string in other case) - normalize_path() and get_absolute_path() work in a lexical level, handling only strings and getting the current path when needed, but without checking the existence of the file
Several refactors in this commit:
Fix #98